import ttkbootstrap as ttk
from ttkbootstrap.constants import *

from management_frame import ManagmentFrame
from student_frame import StudentFrame
from model import *
from untils import center_window

def show_frame(show_frame: ttk.Frame, frames: tuple):
    """ 显示指定框架页面 """
    # 隐藏所有框架
    for f in frames:
        f.pack_forget()
    # 显示指定的框架
    show_frame.pack(fill=BOTH, expand=YES)
    # 如果显示的是“学生信息全量查询”页面，则调用学生查询，以保持数据同步
    if isinstance(show_frame, StudentFrame):
        show_frame._student_list()

if __name__ == "__main__":
    app = ttk.Window(title="学生管理", size=[900, 750])
    app.resizable(FALSE, FALSE)

    # 创建班级与学生综合管理、学生信息全量查询框架界面
    cls_frame = ManagmentFrame(app)
    stu_frame = StudentFrame(app)
    frames = [cls_frame, stu_frame]

    # 导航按钮栏
    buttonbar = ttk.Frame(app, style="primary.TFrame")
    buttonbar.pack(fill=X, pady=1, side=TOP)

    btn = ttk.Button(
        master=buttonbar,
        text="班级与学生综合管理",
        style=INFO,
        command=lambda: show_frame(cls_frame, frames)
    )
    btn.pack(side=LEFT, ipadx=5, ipady=5, padx=(1, 0), pady=1)

    btn = ttk.Button(
        master=buttonbar,
        text="学生信息全量查询",
        style=INFO,
        command=lambda: show_frame(stu_frame, frames)
    )
    btn.pack(side=LEFT, ipadx=5, ipady=5, padx=(1, 0), pady=1)

    # 默认显示班级与学生综合管理
    show_frame(cls_frame, frames)

    center_window(app)

    app.mainloop()
